package com.gupao.adapter.loginadapter.v2;

import com.gupao.adapter.loginadapter.ResultMsg;
import com.gupao.adapter.loginadapter.v1.service.LoginService;
import com.gupao.adapter.loginadapter.v2.adapters.*;

public class PassportForThridAdapter extends LoginService implements IPassportForThird {

    private ResultMsg processLogin(String key, Class<? extends LoginAdapter> clazz){
        try {
            LoginAdapter adapter = clazz.newInstance();
            if(adapter.support(adapter)){
                return adapter.Login(key, adapter);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public ResultMsg loginForQQ(String id) {
        return processLogin(id, LoginForQQAdapter.class);
    }

    public ResultMsg loginForWechat(String id) {
        return processLogin(id, LoginForWechatAdapter.class);
    }

    public ResultMsg loginForToken(String token) {
        return processLogin(token, LoginForTokenAdapter.class);
    }

    public ResultMsg loginFroTelphone(String telphone, String code) {
        return processLogin(telphone, LoginForTellAdapter.class);
    }

    public ResultMsg loginForRegist(String username, String password) {
        super.regist(username,password);
        return super.login(username,password);
    }
}
